package crack.lshape.tri_structure_mesh;

import java.io.IOException;

import crack.AbstractLshapeUsingSDAElementDemo;

import math2.MathUtilities;
import fem2.AbstractStructuralCrackDemo;
import fem2.Element;
import fem2.MaterialModel;
import fem2.Mesh;
import fem2.MeshGenerator;
import fem2.MeshPart;
import fem2.Model;
import fem2.element.crack_sda.SKONConstantJumpCSTElement;
import fem2.material.cohesive_law.CohesiveLaw;
import fem2.material.cohesive_law.Mode1JirasekExponentialCohesiveLaw;
import fem2.pre_and_post.GidMeshGenerator;

public class LshapeTriStructuredMeshSKONConstantJumpCSTElementAndJirasekExponentialCohesiveLaw
		extends AbstractLshapeUsingSDAElementDemo {

	public LshapeTriStructuredMeshSKONConstantJumpCSTElementAndJirasekExponentialCohesiveLaw() {
		meshFileName = "mesh4-skon-jirasek.msh";
	}

	@Override
	public Mesh createMesh() {
		String fn = projectDir + '/' + projectName + '/' + meshFileName;
		MeshGenerator mg = new GidMeshGenerator(fn);
		Mesh mesh = mg.getMesh(2);
		return mesh;
	}

	@Override
	public CohesiveLaw createCohesiveLaw(Model m) {
		double ft = 2.7;
		double Gf = 0.065;
		double Dnn = 1;
		double Dmm = 1;
		return new Mode1JirasekExponentialCohesiveLaw(Gf, ft, Dnn, Dmm);
	}

	@Override
	public Element createElement(MeshPart mp, MaterialModel mm, CohesiveLaw cl) {
		Element e = new SKONConstantJumpCSTElement(mp, mm, cl);
		// e.setEchoLevel(EchoLevelType.OUTPUT);
		return e;
	}

	public static void main(String[] args) throws IOException {

		AbstractStructuralCrackDemo sample = new LshapeTriStructuredMeshSKONConstantJumpCSTElementAndJirasekExponentialCohesiveLaw();

		// double[] lambda = MyLinAlg.createLambdaArray(10.95, 0.05, 11);
		// double[] lambda = MyLinAlg.createLambdaArray(10.95, 0.05, 15);
		// double[] lambda = MyLinAlg.createLambdaArray(10.95, 0.05, 25);
		// double[] lambda = MyLinAlg.createLambdaArray(10.95, 0.1, 35);
		// double[] lambda = MyLinAlg.createLambdaArray(10.95, 0.1, 45);
		double[] lambda = MathUtilities.createLambdaArray(10.95, 0.1, 55); // converged
																		// but
																		// bad
																		// result

		sample.run(lambda);

	}
}
